<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Login</title>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport"
		  content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	<link rel="apple-touch-icon" sizes="76x76" href="/images/logo.png" />
	<link rel="icon" href="/images/logo.png" type="image/x-icon"/>

	<script>
        if (window != window.top) top.location.href = self.location.href;
	</script>

	<link href="/plugins/layui/css/layui.css" rel="stylesheet" />
	<link href="/plugins/font-awesome/css/font-awesome.css" rel="stylesheet" />
	<link href="/css/login.css" rel="stylesheet" />
	<link href="/plugins/sideshow/css/normalize.css" rel="stylesheet" />
	<link href="/plugins/sideshow/css/demo.css" rel="stylesheet" />
	<link href="/plugins/sideshow/css/component.css" rel="stylesheet" />

	<link href="/css/material-bootstrap-wizard.css" rel="stylesheet" />
	<!--  Plugin for the Wizard -->
	<script src="/js/material-bootstrap-wizard.js"></script>

	<style>
		canvas {
			position: absolute;
			z-index: -1;
		}

		.kit-login-box header h1 {
			line-height: normal;
		}

		.kit-login-box header {
			height: auto;
		}

		.content {
			position: relative;
		}

		.codrops-demos {
			position: absolute;
			bottom: 0;
			left: 40%;
			z-index: 10;
		}

		.codrops-demos a {
			border: 2px solid rgba(242, 242, 242, 0.41);
			color: rgba(255, 255, 255, 0.51);
		}

		.kit-pull-right button, .kit-login-main .layui-form-item input {
			background-color: transparent;
			color: white;
		}

		.kit-login-main .layui-form-item input::-webkit-input-placeholder {
			color: white;
		}

		.kit-login-main .layui-form-item input:-moz-placeholder {
			color: white;
		}

		.kit-login-main .layui-form-item input::-moz-placeholder {
			color: white;
		}

		.kit-login-main .layui-form-item input:-ms-input-placeholder {
			color: white;
		}

		.kit-pull-right button:hover {
			border-color: #009688;
			color: #009688
		}
	</style>

</head>


<body class="kit-login-bg">
	
	<!--  Made With Material Kit  -->
	<a href="/" class="made-with-mk">
		<div class="brand"><img src="/images/logo.png" width="24px" /></div>
		<div class="made-with">码乎社区&nbsp;&nbsp;&nbsp;<strong>首页</strong></div>
	</a>
	
	<div class="container demo-2">
		<div class="content">
			<div id="large-header" class="large-header">
				<canvas id="demo-canvas"></canvas>
				<div class="kit-login-box">
					<header>
							<h1><img src="/images/logo.png" height="60px"/>&nbsp;&nbsp;&nbsp;码乎社区登录</h1>
					</header>
					<div class="kit-login-main">
						<form action="/admin/doLogin" class="layui-form" method="post"
							id="loginForm">
							<div class="layui-form-item">
								<label class="kit-login-icon"> <i class="layui-icon">&#xe612;</i>
								</label> <input type="text" name="userName" lay-verify="required"
									autocomplete="off" placeholder="这里管理员账号名" class="layui-input" id="userName">
							</div>
							<div class="layui-form-item">
								<label class="kit-login-icon"> <i class="layui-icon">&#xe642;</i>
								</label> <input type="password" name="password" lay-verify="required" id="password"
									autocomplete="off" placeholder="这里输入密码" class="layui-input">
							</div>
							<div class="layui-form-item">
								<label class="kit-login-icon"> <i class="layui-icon">&#xe642;</i>
								</label> <input type="text" name="captcha" lay-verify="required"
									autocomplete="off" placeholder="输入验证码" class="layui-input">
								<span class="form-code" id="changeCode"
									style="position: absolute; right: 2px; top: 2px;"> <img
									src="/checkImg" id="refImg"
									style="cursor: pointer; height: 34px;" title="点击刷新" />
								</span>
							</div>
							<div class="layui-form-item">
								<div class="kit-pull-left kit-login-remember">
									<input type="checkbox" name="rememberMe" value="true"
										lay-skin="primary" checked title="记住帐号?">
								</div>
								<div class="kit-pull-right">
									<button class="layui-btn layui-btn-primary" lay-submit
										lay-filter="login">
										<i class="fa fa-sign-in" aria-hidden="true"></i> 登录
									</button>
								</div>
								<div class="kit-clear"></div>
							</div>
						</form>
					</div>
					<footer>
						<p>
							<a href="https://xiaojianblog.top/"><img src="/images/favicon.ico"  height="40px"/></a>
								<span style="color: white; font-size: 20px;">&nbsp;&nbsp;&nbsp;官方博客&nbsp;&nbsp;&nbsp;</span>
							<a href="https://jinzzcc.top/"><img src="/images/favicon2.ico"  height="40px"/></a>
						</p>
					</footer>
				</div>
			</div>
		</div>
	</div>
	<!-- /container -->

	<script src="/plugins/layui/layui.js"></script>
	<script src="/plugins/sideshow/js/TweenLite.min.js"></script>
	<script src="/plugins/sideshow/js/EasePack.min.js"></script>
	<script src="/plugins/sideshow/js/rAF.js"></script>
	<script src="/plugins/sideshow/js/demo-2.js"></script>

	<script>

    layui.use(['layer', 'form'], function () {
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form;

        $.ajax({
            url: '/admin/checkUserInSession',
            dataType:'json',
            success:function(res){
                if(res.code==200){
                    var data = res.data;
                    $("#userName").val(data.userName);
                    $("#password").val(data.password);
                    renderForm();//表单重新渲染，要不然添加完显示不出来新的option
                }
            }
        });

        $('#changeCode').on('click', function () {
            var d = new Date();
            $('#changeCode > img')[0].src = '/checkImg?t=' + d.toString(40);
        });

        //清理左侧菜单缓存
        var index = layer.load(2, {
            shade: [0.3, '#333']
        });

        $(window).on('load', function () {
            layer.close(index);
            form.on('submit(login)', function (data) {
                $.post(data.form.action, data.field, function (res) {
                    if(res.code==200){
                        window.location.href = '/admin/index';
                    }else if (res.code==201) {
                        window.location.href = '/';
                    } else {
                        layer.msg(res.msg, {
                            icon: 2
                        });
                        $('#changeCode').click(); //刷新验证码
                    }
                }, 'json');
                return false;
            });
        }());

    });

    //重新渲染表单
    function renderForm(){
        layui.use('form', function(){
            var form = layui.form;//高版本建议把括号去掉，有的低版本，需要加()
            form.render();
        });
    }
</script>
</body>

</html>